require('./PageZlhome.styl');

import {Grid, Group, Note, Popup, TabBar, Toast} from 'saltui';
import reactMixin from 'react-mixin';
import Store from './store';
import Reflux from 'reflux';
import Actions from './actions'
import {Control} from 'react-keeper'
import {zlTabBarItems} from './../../contas/contas.js';
import {PropTypes} from "prop-types";
import {is} from 'immutable'

class Page extends React.Component {

  constructor(props) {
    super(props);
  }


  handleRoute(obj) {
    switch (obj.route) {
      case "native":
        dd.device.notification.alert({
          title: "提示",
          message: "敬请期待",
          buttonName: "确定",
          onSuccess: function (data) {
          },
          onFail: function (err) {
          }
        });
        break;
      default:
        Control.go(obj.route);
        break;
    }
  }

  componentDidMount(){
    console.log(33)


    if (this.context.router.props.location.pathname.indexOf('zllist') > 0) {
      Actions.tabBarChange(0);
    } else if (this.context.router.props.location.pathname.indexOf('zljdjllist') > 0) {
      Actions.tabBarChange(1);
    } else {
      Actions.tabBarChange(0);
    }
  }

  componentWillMount() {

    Popup.hide();



    dd.biz.navigation.setTitle({
      title: '监督工作',//控制标题文本，空字符串表示显示默认文本
      onSuccess: function (result) {
      },
      onFail: function (err) {
      }
    });

    dd.biz.navigation.setRight({
      show: false,//控制按钮显示， true 显示， false 隐藏， 默认true
      control: false,//是否控制点击事件，true 控制，false 不控制， 默认false
      text: '',//控制显示文本，空字符串表示显示默认文本
    });

    dd.device.notification.hidePreloader();

  }

  onTabBarChange(activeIndex) {

    dd.device.notification.showPreloader({
      text: "加载中...", //loading显示的字符，空表示不显示文字
      showIcon: true, //是否显示icon，默认true
    });

    Actions.tabBarChange(activeIndex);


    if (activeIndex == 0) {
      Control.replace('zljdhome/zllist')
    } else if (activeIndex > 0) {
      Control.replace('zljdhome/zljdjllist')
    }
  }

  render() {
    return (
      <div className="jdhome">
        {this.props.children}

        <TabBar activeIndex={this.state.zljdhome.activeIndex}
                onChange={this.onTabBarChange.bind(this)}
                iconHeight={27}
                items={zlTabBarItems}
        />
      </div>
    );
  }

  shouldComponentUpdate(nextProps = {}, nextState = {}) {
    const thisProps = this.props || {},
      thisState = this.state.zljdhome || {};

    if (Object.keys(thisProps).length !== Object.keys(nextProps).length ||
      Object.keys(thisState).length !== Object.keys(nextState).length) {
      return true;
    }

    for (const key in nextProps) {
      if (thisProps[key] !== nextProps[key] || !is(thisProps[key], nextProps[key])) {
        console.log(thisProps[key], nextProps[key]);
        return true;
      }
    }

    for (const key in nextState) {
      if (thisState[key] !== nextState[key] || !is(thisState[key], nextState[key])) {
        return true;
      }
    }
    return false;
  }
}

Page.contextTypes = {
  router: PropTypes.object.isRequired,
  location: PropTypes.object.isRequired,
};


reactMixin.onClass(Page, Reflux.connect(Store, "zljdhome"));

export default Page;
